home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / OS / FWGraphx / Sources / FWGrUtil.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  6.8 KB  |  305 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWGrUtil.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWGRUTIL_H
  13. #include "FWGrUtil.h"
  14. #endif
  15.  
  16. #ifndef FWRECT_H
  17. #include "FWRect.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWDFAULT_H
  25. #include "FWDfault.h"
  26. #endif
  27.  
  28. // ----- OpenDoc Includes -----
  29.  
  30. #ifndef _SHAPE_
  31. #include <Shape.h>
  32. #endif
  33.  
  34. #ifndef _TRNSFORM_
  35. #include <Trnsform.h>
  36. #endif
  37.  
  38. #ifndef _EXCEPT_
  39. #include <Except.h>
  40. #endif
  41.  
  42. // ----- Macintosh Includes -----
  43.  
  44. #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
  45. #include <math routines.h>
  46. #endif
  47.  
  48. //==============================================================================
  49. //    •• RunTime Info
  50. //==============================================================================
  51.  
  52. #ifdef FW_BUILD_MAC
  53. #pragma segment fwgraphx
  54. #endif
  55.  
  56. //==============================================================================
  57. //    •• Global Methods
  58. //==============================================================================
  59.  
  60. //------------------------------------------------------------------------------
  61. // ::InitGraphic
  62. //------------------------------------------------------------------------------
  63.  
  64. void InitGraphic()
  65. {
  66. #ifdef FW_BUILD_MAC
  67.     Rect rBounds;
  68.     ::SetRect(&rBounds, 0, 0, 10 , 10);
  69.     gGraphicGlobales.gScratchWindow = ::NewCWindow(NULL,
  70.                                                     &rBounds,
  71.                                                     "\p",
  72.                                                     FALSE,
  73.                                                     documentProc,
  74.                                                     NULL,
  75.                                                     FALSE,
  76.                                                     0);
  77. #endif
  78. }
  79.  
  80. //------------------------------------------------------------------------------
  81. // ::InsetXMPShape 
  82. //------------------------------------------------------------------------------
  83.  
  84. void InsetXMPShape(XMPShape *shape, short xInset, short yInset)
  85. {
  86. // [HLX] needs to implement GX
  87.     if (shape->IsRectangular())
  88.     {
  89.         FW_CRect rect;
  90.         shape->GetBoundingBox(&rect);
  91.         rect.Inset(ff(xInset), ff(yInset));
  92.         shape->SetRectangle(&rect);
  93.     }
  94.     else
  95.     {
  96.         FW_PlatformRegion shapeRgn = shape->GetQDRegion();
  97.         ::InsetRgn(shapeRgn, xInset, yInset);
  98.         shape->SetQDRegion(shapeRgn);
  99.     }
  100.  
  101. //------------------------------------------------------------------------------
  102. // ::GetXMPShapeQDBox
  103. //------------------------------------------------------------------------------
  104.  
  105. void GetXMPShapeQDBox(XMPShape *shape, FW_SPlatformRect& rect)
  106. {
  107.     FW_CRect box;
  108.     shape->GetBoundingBox(&box);
  109.     rect = box;
  110. }
  111.  
  112. //------------------------------------------------------------------------------
  113. // ::NewXMPShape
  114. //------------------------------------------------------------------------------
  115.  
  116. XMPShape* NewXMPShape(const FW_SPlatformRect& rect)
  117. {
  118.     return NewXMPShape(FW_CRect(rect));
  119. }
  120.  
  121. //------------------------------------------------------------------------------
  122. // ::NewXMPShape
  123. //------------------------------------------------------------------------------
  124.  
  125. XMPShape* NewXMPShape(const FW_CRect& rect)
  126. {
  127.     XMPShape *shape  =  NULL;
  128.     FW_VOLATILE(shape);
  129.     
  130.     TRY
  131.         shape = new XMPShape;
  132.         FailNULL(shape, kXMPErrOutOfMemory);
  133.         FW_CRect notConst(rect);
  134.         shape->SetRectangle(¬Const);
  135.     
  136.     CATCH_ALL
  137.         
  138.         if (shape!=NULL)
  139.             delete shape;
  140.             
  141.         RERAISE;
  142.         
  143.     ENDTRY
  144.     
  145.     return shape;
  146. }
  147.  
  148. //------------------------------------------------------------------------------
  149. // ::NewXMPShape
  150. //------------------------------------------------------------------------------
  151.  
  152. XMPShape* NewXMPShape(FW_PlatformRegion rgn)
  153. {
  154.     XMPShape *shape  =  NULL;
  155.     FW_VOLATILE(shape);
  156.     
  157.     TRY
  158.         shape = new XMPShape;
  159.         FailNULL(shape, kXMPErrOutOfMemory);
  160.         shape->SetPlatformShape(kXMPQuickDraw, rgn);
  161.     
  162.     CATCH_ALL
  163.         
  164.         if (shape!=NULL)
  165.             delete shape;
  166.             
  167.         RERAISE;
  168.         
  169.     ENDTRY
  170.     
  171.     return shape;
  172. }
  173.  
  174. //------------------------------------------------------------------------------
  175. // ::NewXMPShape
  176. //------------------------------------------------------------------------------
  177.  
  178. XMPShape* NewXMPShape()
  179. {
  180.     XMPShape *shape = new XMPShape;
  181.     FailNULL(shape, kXMPErrOutOfMemory);
  182.     
  183.     FW_CRect rect(0,0,0,0);
  184.     shape->SetRectangle(&rect);
  185.     
  186.     return shape;
  187. }
  188.  
  189. //------------------------------------------------------------------------------
  190. // ::NewXMPShape
  191. //------------------------------------------------------------------------------
  192.  
  193. XMPShape* NewXMPShape(XMPShape* otherShape)
  194. {
  195.     XMPShape *shape  =  NULL;
  196.     FW_VOLATILE(shape);
  197.     
  198.     TRY
  199.         shape = new XMPShape;
  200.         FailNULL(shape, kXMPErrOutOfMemory);
  201.         shape->CopyFrom(otherShape);
  202.     
  203.     CATCH_ALL
  204.         
  205.         if (shape!=NULL)
  206.             delete shape;
  207.             
  208.         RERAISE;
  209.         
  210.     ENDTRY
  211.     
  212.     return shape;
  213. }
  214.  
  215. //------------------------------------------------------------------------------
  216. // ::NewXMPTransform
  217. //------------------------------------------------------------------------------
  218.  
  219. XMPTransform* NewXMPTransform()
  220. {
  221.     XMPTransform *transform = new XMPTransform;
  222.     FailNULL(transform, kXMPErrOutOfMemory);
  223.     
  224.     return transform;
  225. }
  226.  
  227. //------------------------------------------------------------------------------
  228. // ::NewXMPTransform
  229. //------------------------------------------------------------------------------
  230.  
  231. XMPTransform* NewXMPTransform(XMPTransform* otherTransform)
  232. {
  233.     XMPTransform *transform  =  NULL;
  234.     FW_VOLATILE(transform);
  235.     
  236.     TRY
  237.         transform = new XMPTransform;
  238.         FailNULL(transform, kXMPErrOutOfMemory);
  239.         transform->CopyFrom(otherTransform);
  240.     
  241.     CATCH_ALL
  242.         
  243.         if (transform!=NULL)
  244.             delete transform;
  245.             
  246.         RERAISE;
  247.         
  248.     ENDTRY
  249.     
  250.     return transform;
  251. }
  252.  
  253. //------------------------------------------------------------------------------
  254. // ::NewXMPTransform
  255. //------------------------------------------------------------------------------
  256.  
  257. XMPTransform* NewXMPTransform(const FW_CPoint& offset)
  258. {
  259.     XMPTransform *transform  =  NULL;
  260.     FW_VOLATILE(transform);
  261.     
  262.     TRY
  263.         transform = new XMPTransform;
  264.         FailNULL(transform, kXMPErrOutOfMemory);
  265.         transform->MoveBy(offset);
  266.     
  267.     CATCH_ALL
  268.         
  269.         if (transform!=NULL)
  270.             delete transform;
  271.             
  272.         RERAISE;
  273.         
  274.     ENDTRY
  275.     
  276.     return transform;
  277. }
  278.  
  279. #ifdef FW_BUILD_MAC
  280. //------------------------------------------------------------------------------
  281. // ::GetPortTextStyle: 
  282. //------------------------------------------------------------------------------
  283.  
  284. void GetPortTextStyle(TextStyle& theTextStyle)
  285. {
  286.     theTextStyle.tsFont = XMPASLMQDGlobals.thePort->txFont;
  287.     theTextStyle.tsFace = XMPASLMQDGlobals.thePort->txFace;
  288.     theTextStyle.tsSize = XMPASLMQDGlobals.thePort->txSize;
  289. }
  290. #endif
  291.  
  292. #ifdef FW_BUILD_MAC
  293. //------------------------------------------------------------------------------
  294. // ::SetPortTextStyle: 
  295. //------------------------------------------------------------------------------
  296.  
  297. void SetPortTextStyle(const TextStyle& theTextStyle)
  298. {
  299.     ::TextFont(theTextStyle.tsFont);
  300.     ::TextFace(theTextStyle.tsFace);
  301.     ::TextSize(theTextStyle.tsSize);
  302. #endif
  303.